package com.jjlin.chapter_8;

import java.util.*;
public class CD40{

    public static int maxGap(int[] nums){
        if(nums == null || nums.length < 2)
            return 0;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        for(int i = 0; i < nums.length; i++){
            max = Math.max(max, nums[i]);
            min = Math.min(min, nums[i]);
        }
        if(max == min)
            return 0;
        int len = nums.length;
        boolean[] hasNum = new boolean[len + 1];
        int[] maxs = new int[len + 1];
        int[] mins = new int[len + 1];
        for(int i = 0; i < len; i++){
            int bid = bucket(nums[i], len, max, min);
            maxs[bid] = hasNum[bid] ? Math.max(maxs[bid], nums[i]) : nums[i];
            mins[bid] = hasNum[bid] ? Math.min(mins[bid], nums[i]) : nums[i];
            hasNum[bid] = true;
        }
        int res = 0;
        int lastMax = maxs[0];
        for(int i = 1; i <= len; i++){
            if(hasNum[i]){
                res = Math.max(res, mins[i] - lastMax);
                lastMax = maxs[i];
            }
        }
        return res;
    }

    //使用long防止溢出
    public static int bucket(long num, long len, long max, long min){
        return (int)((num - min) * len / (max - min));
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int count = sc.nextInt();
        int[] nums = new int[count];
        for(int i = 0; i < count; i++)
            nums[i] = sc.nextInt();
        System.out.println(maxGap(nums));
    }
}